const Router = require('koa-router');
const comment= new Router();
const sqldata = require('./sqldata');

comment.get('/', async (ctx)=>{
    let val=ctx.request.query;
    let mydata = await new Promise((resolve, reject)=>{
        let sql = `select * from comment,user where comment.Uid=user.Uid`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    ctx.body = mydata;
})
comment.delete('/',async(ctx)=>{
    let val=JSON.parse(ctx.request.body);
    console.log(val)
    console.log(val.Cid)
    let sql;
    let mydata;
    mydata = await new Promise((resolve, reject)=>{
        sql = `delete from comment where Cid='${val.Cid}'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
})

module.exports = comment;